const hre = require('hardhat');

async function main() {
  const target = process.env.ADDRESS || (await hre.ethers.getSigners())[0].address;
  const net = await hre.ethers.provider.getNetwork();
  const block = await hre.ethers.provider.getBlockNumber();
  const balance = await hre.ethers.provider.getBalance(target);
  console.log('=== Network Diagnose ===');
  console.log('Hardhat network name:', hre.network.name);
  console.log('RPC chainId:', net.chainId.toString());
  console.log('Current block:', block);
  console.log('Address:', target);
  console.log('Balance (wei):', balance.toString());
  console.log('Balance (ETH):', hre.ethers.formatEther(balance));
}

main().catch(e=>{console.error(e);process.exit(1);});
